<?php
class service extends common{
	
	function __construct(){	
		$pagec = new page($_GET['page']);
		parent::__construct($pagec);
	}	
	private $table_service_class = 'zs_service_class';	//分类
	private $table_service = 'zs_service';				//服务

	private $table_service_album = 'zs_service_album';	//相册

	private $table_service_comment='zs_service_comment'; //评论表
	private $table_user='user'; //用户表

	/**
	 * 分类列表
	 * @author	jsy
	 * @param	string	$where  
	 * @param	string	$key 
	 * @param	int	$is_page  
	 * @return 	array
	 */

	function service_class_list($where='',$key="c.*",$is_page=false){
		$sql = $this->table_service_class." c WHERE 1=1 ".$where." order by c.id " ;
		if($is_page){
			$sql_num = $sql;
		}else{
			$sql_num = "";
		}
		$res = $this->getList($sql,$sql_num,$key);
		return $res ;
	}

	/**
	 * 单个分类详情
	 * @author	jsy
	 * @param	int	    $id
	 * @param	string	$key
	 * @return	array
	 */
	function class_info($id,$key="*"){
		if($id != null && $id != ""){
			$row = $this->getInfo($this->table_service_class,$id,$key,'id');		
		}
		return $row;
	}


	/**
	 * 服务添加
	 * @author	jsy	
	 * @param	array	$arr 		//批量
	 * @return 	bool
	 */
	function service_add($arr){
		if(!empty($arr)){
			$res = $this->insert($this->table_service,$arr);	//插入活动
			// $id = $this->insert_id();	
		}
		return $res;
	}

	/**
	 * 服务修改
	 * @author	jsy
	 * @param 	int	 	$id
	 * @param	array	$arr  
	 * @return	bool
	 */
	function service_update($id,$arr){
		if( is_array($arr)){
			$res=$this->update($this->table_service,$arr,"id=".$id);
		}
		return $res;
	}

	/**
	 * 服务详情
	 * @author	jsy
	 * @param	int	    $id
	 * @param	string	$key
	 * @return	array
	 */
	function service_info($id,$key="*"){
		if($id != null && $id != ""){
			$row = $this->getInfo($this->table_service,$id,$key,'id');		
		}
		return $row;
	}

	/**
	 *服务列表
	 * @author	jsy
	 * @param	string	$where
	 * @param	string	$key 
	 * @return 	array
	 */
	function service_list($where='',$key="s.*"){
		$sql = $this->table_service." s WHERE 1=1 ".$where."  ORDER BY s.create_time desc";
		$res = $this->getList($sql,$sql,$key);
		return $res;
	}


	/**
	 *相册列表
	 * @author	jsy
	 * @param	string	$where
	 * @param	string	$key 
	 * @return 	array
	 */
	function service_album_list($where='',$key="s.*"){
		$sql = $this->table_service_album." s WHERE 1=1 ".$where."  ORDER BY s.sort ";
		$res = $this->getList($sql,$sql,$key);
		return $res;
	}

	
	/**
	 * 服务评论
	 * @author	jsy 
	 * @param	string	$where  
	 * @param	string	$key  
	 * @return 	array
	 */
	function serviceComment($where='',$key="*"){
		$sql = $this->table_service_comment." a LEFT JOIN ".$this->table_user." u ON a.user_id=u.id LEFT JOIN ".$this->table_user." u1 ON a.reply_id=u1.id WHERE 1=1  ".$where." order by a.create_time desc" ;
		$res=$this->getList($sql,$sql,$key);
		return $res ;
	}
}
?>